/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PaintGUI.java
 *
 * Created on 30.03.2011, 20:23:32
 */
package figurenZeichnen;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 *
 * @author Chris
 */
public class GrafikGUI extends javax.swing.JFrame {

    private int art = 0;
    private Point mousePosition1, mousePosition2;
    private int x1, y1, x2, y2, hoeheK, breiteK;
    private Color color, colorBack;
    private boolean resize = false;

    /** Creates new form PaintGUI */
    public GrafikGUI() {
        initComponents();
        setTitle("Zeichenblatt");
        fTool.setVisible(true);
        fTool.pack();
        fTool.setTitle("Zeichenfunktionen");
        fColor.setTitle("erweiterte Farben");
        fColorBack.setTitle("erweiterte Farben");
        fSettings.setTitle("Einstellungen");

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        fTool = new javax.swing.JFrame();
        pnButtons1 = new javax.swing.JPanel();
        cb1 = new javax.swing.JComboBox();
        cb3 = new javax.swing.JComboBox();
        cb4 = new javax.swing.JComboBox();
        cb2 = new javax.swing.JComboBox();
        btErwColor = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        btSave = new javax.swing.JButton();
        btZeichnen = new javax.swing.JButton();
        btDelete = new javax.swing.JButton();
        fColor = new javax.swing.JFrame();
        cc1 = new javax.swing.JColorChooser();
        btSetColor = new javax.swing.JButton();
        fDateiN = new javax.swing.JFrame();
        pnDateiName = new javax.swing.JPanel();
        lbInName = new javax.swing.JLabel();
        tfInName = new javax.swing.JTextField();
        btOkDN = new javax.swing.JButton();
        btAbort = new javax.swing.JButton();
        fSettings = new javax.swing.JFrame();
        lbBlattW = new javax.swing.JLabel();
        lbBlattH = new javax.swing.JLabel();
        tfBlattW = new javax.swing.JTextField();
        tfBlattH = new javax.swing.JTextField();
        btSize = new javax.swing.JButton();
        btBackColor = new javax.swing.JButton();
        fColorBack = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        cc2 = new javax.swing.JColorChooser();
        jPanel2 = new javax.swing.JPanel();
        btSetColorBack = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        pnPaint = new javax.swing.JPanel();

        pnButtons1.setBorder(javax.swing.BorderFactory.createTitledBorder("Zeichenfunktionen"));
        pnButtons1.setLayout(new java.awt.GridLayout(3, 3));

        cb1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Diagonalen", "Fächer", "konz. Kreise", "Spirale" }));
        pnButtons1.add(cb1);

        cb3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Kreis", "Rechteck", "Linie", "Dreieck" }));
        pnButtons1.add(cb3);

        cb4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "überschreiben", "behalten" }));
        pnButtons1.add(cb4);

        cb2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Schwarz", "Blau", "Cyan", "Dunkel Grau", "Grau", "Grün", "Hell Grau", "Magenta", "Orange", "Pink", "Rot", "Weiß", "Gelb" }));
        cb2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                onSetColor(evt);
            }
        });
        pnButtons1.add(cb2);

        btErwColor.setText("erw. Farben");
        btErwColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onErwFarben(evt);
            }
        });
        pnButtons1.add(btErwColor);

        jButton1.setText("Einstellungen");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onOpenSettings(evt);
            }
        });
        pnButtons1.add(jButton1);

        btSave.setText("Speichern");
        btSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onSave(evt);
            }
        });
        pnButtons1.add(btSave);

        btZeichnen.setText("Zeichnen");
        btZeichnen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onPaint(evt);
            }
        });
        pnButtons1.add(btZeichnen);

        btDelete.setText("Alles löschen");
        btDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onDelete(evt);
            }
        });
        pnButtons1.add(btDelete);

        fTool.getContentPane().add(pnButtons1, java.awt.BorderLayout.CENTER);

        fColor.getContentPane().add(cc1, java.awt.BorderLayout.CENTER);

        btSetColor.setText("Farbe setzen");
        btSetColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setErwColor(evt);
            }
        });
        fColor.getContentPane().add(btSetColor, java.awt.BorderLayout.PAGE_END);

        pnDateiName.setLayout(new java.awt.GridBagLayout());

        lbInName.setText("Bitte geben Sie einen Dateinamen ein:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        pnDateiName.add(lbInName, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        pnDateiName.add(tfInName, gridBagConstraints);

        btOkDN.setText("Ok");
        btOkDN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onSaveName(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        pnDateiName.add(btOkDN, gridBagConstraints);

        btAbort.setText("Abbrechen");
        btAbort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onAbort(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        pnDateiName.add(btAbort, gridBagConstraints);

        fDateiN.getContentPane().add(pnDateiName, java.awt.BorderLayout.CENTER);

        fSettings.getContentPane().setLayout(new java.awt.GridBagLayout());

        lbBlattW.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbBlattW.setText("Blattbreite:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        fSettings.getContentPane().add(lbBlattW, gridBagConstraints);

        lbBlattH.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbBlattH.setText("Blatthöhe:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        fSettings.getContentPane().add(lbBlattH, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        fSettings.getContentPane().add(tfBlattW, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        fSettings.getContentPane().add(tfBlattH, gridBagConstraints);

        btSize.setText("Größe ändern");
        btSize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onSetSize(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        fSettings.getContentPane().add(btSize, gridBagConstraints);

        btBackColor.setText("Hintergrundfarbe");
        btBackColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onSetBackColor(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        fSettings.getContentPane().add(btBackColor, gridBagConstraints);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 434, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 2, Short.MAX_VALUE)
                    .addComponent(cc2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 3, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 435, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 37, Short.MAX_VALUE)
                    .addComponent(cc2, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 38, Short.MAX_VALUE)))
        );

        fColorBack.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        btSetColorBack.setText("Farbe setzen");
        btSetColorBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSetColorBack(evt);
            }
        });
        jPanel2.add(btSetColorBack);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Achtung! Blatt wird überschrieben!");
        jPanel2.add(jLabel1);

        fColorBack.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pnPaint.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                onkBegin(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                onkEnd(evt);
            }
        });
        pnPaint.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                resized(evt);
            }
        });

        javax.swing.GroupLayout pnPaintLayout = new javax.swing.GroupLayout(pnPaint);
        pnPaint.setLayout(pnPaintLayout);
        pnPaintLayout.setHorizontalGroup(
            pnPaintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 570, Short.MAX_VALUE)
        );
        pnPaintLayout.setVerticalGroup(
            pnPaintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        getContentPane().add(pnPaint, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void onkBegin(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onkBegin
        mousePosition1 = pnPaint.getMousePosition();
        if (fTool.isVisible()) {
        } else {
            fTool.setVisible(true);
        }
    }//GEN-LAST:event_onkBegin

    private void onkEnd(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onkEnd
        mousePosition2 = pnPaint.getMousePosition();
        x1 = mousePosition1.x;
        y1 = mousePosition1.y;
        x2 = mousePosition2.x;
        y2 = mousePosition2.y;
        if (cb3.getSelectedItem().equals("Kreis")) {
            art = 5;
        } else if (cb3.getSelectedItem().equals("Rechteck")) {
            art = 6;
        } else if (cb3.getSelectedItem().equals("Linie")) {
            art = 7;
        } else if (cb3.getSelectedItem().equals("Dreieck")) {
            art = 8;
        }
        repaint();
    }//GEN-LAST:event_onkEnd

    private void onDelete(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onDelete
        cb4.setSelectedItem("überschreiben");
        art = 0;
        repaint();
}//GEN-LAST:event_onDelete

    private void onPaint(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onPaint
        if (cb1.getSelectedItem().equals("Diagonalen")) {
            art = 1;
            repaint();
        } else if (cb1.getSelectedItem().equals("Fächer")) {
            art = 2;
            repaint();
        } else if (cb1.getSelectedItem().equals("konz. Kreise")) {
            art = 3;
            repaint();
        } else if (cb1.getSelectedItem().equals("Spirale")) {
            art = 4;
            repaint();
        }
}//GEN-LAST:event_onPaint

    private void onErwFarben(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onErwFarben
        fColor.setVisible(true);
        fColor.pack();
}//GEN-LAST:event_onErwFarben

    private void onSetColor(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_onSetColor
        if (cb2.getSelectedItem().equals("Schwarz")) {
            color = Color.BLACK;
        } else if (cb2.getSelectedItem().equals("Blau")) {
            color = Color.BLUE;
        } else if (cb2.getSelectedItem().equals("Cyan")) {
            color = Color.CYAN;
        } else if (cb2.getSelectedItem().equals("Dunkel Grau")) {
            color = Color.DARK_GRAY;
        } else if (cb2.getSelectedItem().equals("Grau")) {
            color = Color.GRAY;
        } else if (cb2.getSelectedItem().equals("Grün")) {
            color = Color.GREEN;
        } else if (cb2.getSelectedItem().equals("Hell Grau")) {
            color = Color.LIGHT_GRAY;
        } else if (cb2.getSelectedItem().equals("Magenta")) {
            color = Color.MAGENTA;
        } else if (cb2.getSelectedItem().equals("Orange")) {
            color = Color.ORANGE;
        } else if (cb2.getSelectedItem().equals("Pink")) {
            color = Color.PINK;
        } else if (cb2.getSelectedItem().equals("Rot")) {
            color = Color.RED;
        } else if (cb2.getSelectedItem().equals("Weiß")) {
            color = Color.WHITE;
        } else if (cb2.getSelectedItem().equals("Gelb")) {
            color = Color.YELLOW;
        }
    }//GEN-LAST:event_onSetColor

    private void setErwColor(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setErwColor
        color = cc1.getColor();
        fColor.setVisible(false);
    }//GEN-LAST:event_setErwColor

    private void onSave(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onSave
        fDateiN.setVisible(true);
        fDateiN.pack();
    }//GEN-LAST:event_onSave

    private void onSaveName(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onSaveName
        try {

            String fileName = tfInName.getText();
            Point start = pnPaint.getLocationOnScreen();
            int xB1 = start.x;
            int yB1 = start.y;
            int xB2 = pnPaint.getWidth();
            int yB2 = pnPaint.getHeight();
            Rectangle rectangle = new Rectangle(xB1, yB1, xB2, yB2);

            Robot robot = new Robot();
            BufferedImage image = robot.createScreenCapture(rectangle);
            File file = new File(fileName + ".jpg");
            ImageIO.write((RenderedImage) image, "jpg", file);


        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        fDateiN.dispose();
    }//GEN-LAST:event_onSaveName

    private void onOpenSettings(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onOpenSettings
        fSettings.setVisible(true);
        fSettings.pack();
    }//GEN-LAST:event_onOpenSettings

    private void onSetBackColor(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onSetBackColor
        fColorBack.setVisible(true);
        fColorBack.pack();
    }//GEN-LAST:event_onSetBackColor

    private void btSetColorBack(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSetColorBack
        colorBack = cc2.getColor();
        fColorBack.dispose();
        pnPaint.setBackground(colorBack);
    }//GEN-LAST:event_btSetColorBack

    private void onSetSize(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onSetSize
        int breite = Integer.parseInt(tfBlattW.getText());
        int höhe = Integer.parseInt(tfBlattH.getText());
        this.setSize(breite, höhe);
        pnPaint.repaint();
    }//GEN-LAST:event_onSetSize

    private void onAbort(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onAbort
        fDateiN.dispose();
    }//GEN-LAST:event_onAbort

    private void resized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_resized
        resize = true;
    }//GEN-LAST:event_resized

    @Override
    public void paint(Graphics g1) {
        if (cb4.getSelectedItem().equals("überschreiben") && resize == false) {
            super.paint(g1);
        }
        if (art == 1) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);
            }
            Graphics g2 = pnPaint.getGraphics();
            drawDiagonal(g2);
            resize = false;
        } else if (art == 2) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);
            }
            Graphics g3 = pnPaint.getGraphics();
            drawFaecher(g3);
            resize = false;
        } else if (art == 3) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);
            }
            Graphics g4 = pnPaint.getGraphics();
            drawKreise(g4);
            resize = false;
        } else if (art == 4) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);
            }
            Graphics g5 = pnPaint.getGraphics();
            drawSpirale(g5);
            resize = false;
            
        } else if (art == 5) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);

            }
            Graphics g6 = pnPaint.getGraphics();
            drawZKreis(g6);
            resize = false;
        } else if (art == 6) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);

            }
            Graphics g7 = pnPaint.getGraphics();
            drawZRechteck(g7);
            resize = false;
        } else if (art == 7) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);

            }
            Graphics g8 = pnPaint.getGraphics();
            drawZLinie(g8);
            resize = false;
        } else if (art == 8) {
            if (cb4.getSelectedItem().equals("überschreiben")&& resize == false) {
                super.paint(g1);
            }
            Graphics g9 = pnPaint.getGraphics();
            drawDreieck(g9);
            resize = false;
        }
    }

    private void drawDiagonal(Graphics g2) {
        int breite = pnPaint.getWidth();
        int hoehe = pnPaint.getHeight();
        g2.setColor(color);
        g2.drawLine(0, 0, breite, hoehe);
        g2.drawLine(0, hoehe, breite, 0);

    }

    private void drawFaecher(Graphics g3) {
        int hoehe = pnPaint.getHeight();
        int breite = pnPaint.getWidth();
        int hilfsH = 0;
        g3.setColor(color);
        while (hilfsH <= hoehe) {
            g3.drawLine(0, 0, breite, hilfsH);
            hilfsH += 10;
        }

    }

    private void drawKreise(Graphics g4) {
        int hoehe = pnPaint.getHeight();
        int breite = pnPaint.getWidth();
        int breiteN = breite / 2 - 5;
        int hoeheN = hoehe / 2 - 5;
        int hoeheKreis = 10;
        g4.setColor(color);
        while (hoeheKreis < hoehe) {
            g4.drawOval(breiteN, hoeheN, hoeheKreis, hoeheKreis);
            hoeheN -= 5;
            breiteN -= 5;
            hoeheKreis += 10;

        }

    }

    private void drawSpirale(Graphics g5) {
        int hoehe = pnPaint.getHeight();
        int breite = pnPaint.getWidth();
        int mittelpunktH = hoehe / 2;
        int mittelpunktB = breite / 2;
        int dir = 1;
        int tempH = 0;
        int tempB = 0;
        int plusZ = 5;
        g5.setColor(color);
        while (mittelpunktH < hoehe && mittelpunktB < breite) {
            if (dir == 1) {
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                mittelpunktB += plusZ;
                g5.drawLine(tempB, tempH, mittelpunktB, mittelpunktH);
                dir = 2;
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                plusZ += 5;
            } else if (dir == 2) {
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                mittelpunktH -= plusZ;
                g5.drawLine(tempB, tempH, mittelpunktB, mittelpunktH);
                dir = 3;
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                plusZ += 5;
            } else if (dir == 3) {
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                mittelpunktB -= plusZ;
                g5.drawLine(tempB, tempH, mittelpunktB, mittelpunktH);
                dir = 4;
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                plusZ += 5;
            } else if (dir == 4) {
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                mittelpunktH += plusZ;
                g5.drawLine(tempB, tempH, mittelpunktB, mittelpunktH);
                dir = 1;
                tempB = mittelpunktB;
                tempH = mittelpunktH;
                plusZ += 5;
            }

        }

    }

    private void drawZKreis(Graphics g6) {
        g6.setColor(color);
        if (y2 < y1 && x2 < x1) {
            //Links oben
            int hoeheZK = y1 - y2;
            int breiteZK = x1 - x2;
            g6.drawOval(x2, y2, breiteZK, hoeheZK);
        } else if (x1 < x2 && y1 > y2) {
            //rechts oben
            int hoeheZK = y1 - y2;
            int breiteZK = x2 - x1;
            y1 = y1 - hoeheZK;
            x1 = x2 - breiteZK;
            g6.drawOval(x1, y1, breiteZK, hoeheZK);
        } else if (x1 < x2 && y1 < y2) {
            //rechts unten
            int hoeheZK = y2 - y1;
            int breiteZK = x2 - x1;
            g6.drawOval(x1, y1, breiteZK, hoeheZK);
        } else if (x1 > x2 && y1 < y2) {
            //links unten
            int hoeheZK = y2 - y1;
            int breiteZK = x1 - x2;
            x1 = x1 - breiteZK;
            g6.drawOval(x1, y1, breiteZK, hoeheZK);
        }
    }

    private void drawZRechteck(Graphics g7) {
        g7.setColor(color);
        if (y2 < y1 && x2 < x1) {
            //Links oben
            int hoeheZR = y1 - y2;
            int breiteZR = x1 - x2;
            g7.drawRect(x2, y2, breiteZR, hoeheZR);
        } else if (x1 < x2 && y1 > y2) {
            //rechts oben
            int hoeheZR = y1 - y2;
            int breiteZR = x2 - x1;
            y1 = y1 - hoeheZR;
            x1 = x2 - breiteZR;
            g7.drawRect(x1, y1, breiteZR, hoeheZR);
        } else if (x1 < x2 && y1 < y2) {
            //rechts unten
            int hoeheZR = y2 - y1;
            int breiteZR = x2 - x1;
            g7.drawRect(x1, y1, breiteZR, hoeheZR);
        } else if (x1 > x2 && y1 < y2) {
            //links unten
            int hoeheZR = y2 - y1;
            int breiteZR = x1 - x2;
            x1 = x1 - breiteZR;
            g7.drawRect(x1, y1, breiteZR, hoeheZR);
        }
    }

    private void drawZLinie(Graphics g8) {
        g8.setColor(color);
        g8.drawLine(x1, y1, x2, y2);
    }

    private void drawDreieck(Graphics g9) {
        g9.setColor(color);
        if (y2 < y1 && x2 < x1) {
            //Links oben
            int breiteD = x1 - x2;
            int hoeheD = y1 - y2;
            int spitze = x2 + breiteD / 2;
            int lineU = y2 + hoeheD;
            g9.drawLine(spitze, y2, x2, lineU);
            g9.drawLine(spitze, y2, x1, lineU);
            g9.drawLine(x2, lineU, x1, lineU);
        } else if (x1 < x2 && y1 > y2) {
            //rechts oben
            int breiteD = x2 - x1;
            int hoeheD = y1 - y2;
            int spitze = x1 + breiteD / 2;
            g9.drawLine(spitze, y2, x1, y1);
            g9.drawLine(spitze, y2, x1 + breiteD, y1);
            g9.drawLine(x1, y1, x1 + breiteD, y1);
        } else if (x1 < x2 && y1 < y2) {
            //rechts unten
            int breiteD = x2 - x1;
            int hoeheD = y2 - y1;
            int spitze = x1 + breiteD / 2;
            g9.drawLine(spitze, y1, x2 - breiteD, y2);
            g9.drawLine(spitze, y1, x2, y2);
            g9.drawLine(x2 - breiteD, y2, x2, y2);

        } else if (x1 > x2 && y1 < y2) {
            //links unten
            int breiteD = x1 - x2;
            int hoeheD = y2 - y1;
            int spitze = x1 - breiteD / 2;
            g9.drawLine(spitze, y1, x2, y2);
            g9.drawLine(spitze, y1, x2 + breiteD, y2);
            g9.drawLine(x2, y2, x2 + breiteD, y2);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GrafikGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAbort;
    private javax.swing.JButton btBackColor;
    private javax.swing.JButton btDelete;
    private javax.swing.JButton btErwColor;
    private javax.swing.JButton btOkDN;
    private javax.swing.JButton btSave;
    private javax.swing.JButton btSetColor;
    private javax.swing.JButton btSetColorBack;
    private javax.swing.JButton btSize;
    private javax.swing.JButton btZeichnen;
    private javax.swing.JComboBox cb1;
    private javax.swing.JComboBox cb2;
    private javax.swing.JComboBox cb3;
    private javax.swing.JComboBox cb4;
    private javax.swing.JColorChooser cc1;
    private javax.swing.JColorChooser cc2;
    private javax.swing.JFrame fColor;
    private javax.swing.JFrame fColorBack;
    private javax.swing.JFrame fDateiN;
    private javax.swing.JFrame fSettings;
    private javax.swing.JFrame fTool;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lbBlattH;
    private javax.swing.JLabel lbBlattW;
    private javax.swing.JLabel lbInName;
    private javax.swing.JPanel pnButtons1;
    private javax.swing.JPanel pnDateiName;
    private javax.swing.JPanel pnPaint;
    private javax.swing.JTextField tfBlattH;
    private javax.swing.JTextField tfBlattW;
    private javax.swing.JTextField tfInName;
    // End of variables declaration//GEN-END:variables
}
